﻿#region 头注释
/******************************************************************************
文件名称    :   HospitalizationService.cs
创建日期    :   2011-4-23 21:58:49
功能描述    :   Hospitalization实体数据服务类
修改日志    :   
    2011-04-23 21:58  马利
*******************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using Stone.Components.Entities;
using Dare.Utilities.Data;
using Stone.Data.Providers;

namespace Stone.Services.EntityServices
{
    /// <summary>
    /// Hospitalization实体数据服务类
    /// </summary>
    public class HospitalizationService : EntityServiceTemplate<Hospitalization, long, HospitalizationDataProvider>
    {
        public HospitalizationService(Application app)
            : base(app)
        {
        }


        public List<Hospitalization> GetAllByPatient(long patientId, string orderBy)
        {
            List<Hospitalization> list = null;
            if (Execute(delegate(TransactionManager manager)
            {
                list = provider.GetAllByPatient(manager, patientId, orderBy);
            }))
            {
                return list;
            }
            else
            {
                return null;
            }
        }


        public bool DeleteHospitalInfo(Hospitalization hospital)
        {
            ChemistryService chemService = Stone.Services.Application.Instance.GetDbService<ChemistryService>();
            ChemistryUrine24hService chem24hurineService = Stone.Services.Application.Instance.GetDbService<ChemistryUrine24hService>();
            ChemistryBiochemistryService chemBiochemistryService = Stone.Services.Application.Instance.GetDbService<ChemistryBiochemistryService>();
            ChemistryBloodService chemBloodService = Stone.Services.Application.Instance.GetDbService<ChemistryBloodService>();
            ChemistryCruorService chemCruorService = Stone.Services.Application.Instance.GetDbService<ChemistryCruorService>();
            ChemistryImmunityService chemImmunityService = Stone.Services.Application.Instance.GetDbService<ChemistryImmunityService>();
            ChemistryLymphocyteService chemLymphocyteService = Stone.Services.Application.Instance.GetDbService<ChemistryLymphocyteService>();
            ChemistryUrineService chemUrineService = Stone.Services.Application.Instance.GetDbService<ChemistryUrineService>();
            OpticsService opticsService = Stone.Services.Application.Instance.GetDbService<OpticsService>();
            SurgeryService surgeryService = Stone.Services.Application.Instance.GetDbService<SurgeryService>();
            SurgeryHardtubeService surgeryHardtubeService = Stone.Services.Application.Instance.GetDbService<SurgeryHardtubeService>();
            SurgeryKidneyService surgeryKidneyService = Stone.Services.Application.Instance.GetDbService<SurgeryKidneyService>();
            SurgerySofttubeService surgerySofttubeService = Stone.Services.Application.Instance.GetDbService<SurgerySofttubeService>();
            SurgeryInfectionService surgeryInfectionService = Stone.Services.Application.Instance.GetDbService<SurgeryInfectionService>();

            try
            {
                if (hospital.ChemistryId.HasValue)
                {
                    Chemistry chem = chemService.Get(hospital.ChemistryId.Value);
                    chemService.DeleteChemistryInfo(chem);
                }
                if (hospital.OpticsId.HasValue)
                {
                    Optics optics = opticsService.Get(hospital.OpticsId.Value);
                    opticsService.DeleteOpticsInfo(optics);
                }
                if (hospital.SurgeryId.HasValue)
                {
                    Surgery surgery = surgeryService.Get(hospital.SurgeryId.Value);
                    surgeryService.DeleteSurgeryInfo(surgery);
                }

                return Delete(hospital.Id);
            }
            catch
            {
                return false;
            }
        }

        public List<Hospitalization> GetAllByPatientPaged(long patientId, string orderBy, int pageIndex, int pageSize, out int totalCount)
        {
            List<Hospitalization> list = null;
            int itemCount = 0;
            if (Execute(delegate(TransactionManager manager)
            {
                list = provider.GetAllByPatientPaged(manager, patientId, orderBy, pageIndex, pageSize, out itemCount);
            }))
            {
                totalCount = itemCount;
                return list;
            }
            else
            {
                totalCount = -1;
                return null;
            }
        }
    }
}
